<?php

register_shutdown_function('shutdown_function');
session_start();
ini_set('date.timezone', 'Asia/Shanghai');
require_once("config.php");
require_once("source/common.php");
require_once("source/myfun.php");
if (APP_DEBUG) {
    ini_set('display_errors', 'On');
    error_reporting(E_WARNING | E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING);
} else {
    error_reporting(0);
}
if ($_POST) {
    foreach ($_POST as $k => $v) {
        $_POST[$k] = inputFilter($v);
    }
}
$tp = $_GET["tp"];
if (empty($tp)) {
    echo 'welcome';
    exit;
} else {
    if (strpos($tp, '.') !== false) {
        echo echojson('illegal access', 0);
        exit;
    }
    $uid = (int) $_GET['uid'];
    $imei = $_GET['imei'];
    $pt = (int) $_GET['pt'];
    $ver = $_GET['ver'];
    $appid = (int) $_GET['appid'];
    $sign = $_GET['sign'];
    $op = $_GET['op'];
    $key = constant("KEY");
    $host = constant("HOST");
    $isSHB = 0;

    if (strstr($tp, 'front')) {
    	$tpl = init_smarty();
    
    	$tpl->assign("uid", $uid);
    	$tpl->assign("imei", $imei);
    	$tpl->assign("pt", $pt);
    	$tpl->assign("ver", $ver);
    	$tpl->assign("appid", $appid);
    	$tpl->assign("sign", $sign);
    	$tpl->assign("tp", $tp);
    	$tpl->assign("op", $op);
    	$tpl->assign("host", $host);
    }else {
    	header("Content-type: application/json;charset=utf-8");
    }
    
    include_once(S_ROOT . "source/{$tp}.php");
}
function shutdown_function()
{
    $e = error_get_last();
    if($e['type']==E_ERROR||$e['type']==E_PARSE||$e['type']==E_CORE_ERROR||$e['type']==E_CORE_WARNING)
    {
        writelog('errors.txt',$e['message'].' in '.$e['file'].' line:'.$e['line'].' '.$e['type']);
    }
}